Skip to content

Сукач Данил Лаб. 1 Группа 6511#6

Open
DanilSukach wants to merge 3 commits intoitsecd:mainfrom
DanilSukach:main
Open

Сукач Данил Лаб. 1 Группа 6511#6
DanilSukach wants to merge 3 commits intoitsecd:mainfrom
DanilSukach:main

Conversation

@DanilSukach
Copy link

ФИО: Сукач Данил
Номер группы: 6511
Номер лабораторной: 1
Номер варианта: 15
Краткое описание предметной области: Кредитная заявка
**Краткое описание добавленных фич:**Добавлен сервис генерации и кэширование через redis

@github-actions github-actions bot added In progress Код в процессе проверки Lab 1 Лабораторная №1. Кэширование labels Feb 18, 2026
@github-actions github-actions bot requested a review from danlla February 18, 2026 12:21
Copy link

@danlla danlla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выглядит немного как оверинжиниринг, много интерфейсов, у которых больше одной имплементации точно не будет, выделение в либу генератора, хотя он неплохо бы смотрелся как сервис в апи

В принципе оно выглядит хорошо и если так хочется, пусть так будет

При старте Apire отдельно в браузере запускается клиент, что не очень удобно, можно отключить это в launchsettings.json клиента

Comment on lines 13 to 51
var faker = new Faker();

var status = faker.PickRandom(CreditDictionaries.Statuses);

var submissionDate = DateOnly.FromDateTime(
faker.Date.Between(DateTime.Now.AddYears(-2), DateTime.Now));

DateOnly? decisionDate = null;
decimal? approvedAmount = null;

var requested = Math.Round(faker.Random.Decimal(100_000, 10_000_000), 2);

if (CreditDictionaries.IsTerminal(status))
{
decisionDate = submissionDate.AddDays(faker.Random.Int(1, 30));

if (status == "Одобрена")
{
approvedAmount = Math.Round(
faker.Random.Decimal(10_000, requested), 2);
}
}

var interestRate = Math.Round(
faker.Random.Double(centralBankRate, centralBankRate + 10), 2);

return Task.FromResult(new CreditApplication
{
Id = id,
CreditType = faker.PickRandom(CreditDictionaries.CreditTypes),
RequestedAmount = requested,
TermMonths = faker.Random.Int(6, 360),
InterestRate = interestRate,
SubmissionDate = submissionDate,
HasInsurance = faker.Random.Bool(),
Status = status,
DecisionDate = decisionDate,
ApprovedAmount = approvedAmount
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Всю генерацию лучше сделать в виде:

var faker = new Faker<CreditApplication>()
    .RuleFor(c => c.Status, f => f.PickRandom(CreditDictionaries.Statuses))
    ...

return faker.Generate();

сам объект faker можно объявить полем/свойством и инициализировать при создании генератора

if (!string.IsNullOrEmpty(cached))
{
logger.LogInformation("Cache HIT {CacheKey}", cacheKey);
return JsonSerializer.Deserialize<CreditApplication>(cached)!;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Теоретически возможно ситуация, что в кэше лежит мусор, который не сможет быть десериализован
Так что тут лучше не использовать null-forgiving operator, а проверить на null и вернуть если все нормально, а если не нормально, то код ниже сгенерирует новый объект по заданному ключу


var options = new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 лучше вынести в appsettings.json

ILogger<CreditService> logger)
: ICreditService
{
public async Task<CreditApplication> GetAsync(int id, CancellationToken ct)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все тело метода стоит в try catch обернуть


builder.AddRedisDistributedCache("credit-cache");

var centralBankRate = builder.Configuration.GetValue<double>("CreditGenerator:CentralBankRate", 16.0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<double> тут не нужен, тип по дефолтному значение подтягивается

/// <param name="ct">Токен отмены для асинхронной операции.</param>
/// <returns>HTTP 200 с объектом заявки при успешном получении.</returns>
[HttpGet]
public async Task<IActionResult> Get([FromQuery] int id, CancellationToken ct)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если использовать сваггер, то нужно нормально настроить генерацию OpenApi:

Task<ActionResult<CreditApplication>>

Только после этого нужно будет добавить еще xml файл из CreditApp.Domain, чтобы у CreditApplication в OpenApi было описание

Можно так же накинуть атрибуты, по типу ProduceResponseType

public class CreditApplicationGenerator(double centralBankRate)
: ICreditApplicationGenerator
{
public Task<CreditApplication> GenerateAsync(int id, CancellationToken ct)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CancellationToken нигде не используется же

Comment on lines 27 to 33
builder.Services.AddCors(options =>
{
options.AddPolicy("DefaultCors",
policy => policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше cors настроить нормально:
Брать из appsettings.json допустимые origins

Для app.Environment.IsDevelopment() можно оставить доступ всем

<UnorderedListItem>Выполнена <Strong>Фамилией Именем 65ХХ</Strong> </UnorderedListItem>
<UnorderedListItem><Link To="https://puginarug.com/">Ссылка на форк</Link></UnorderedListItem>
<UnorderedListItem>Номер <Strong>№1 "Кэширование"</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№2 "Кредитная заявка"</Strong></UnorderedListItem>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вариант 15

<ProjectReference Include="..\CreditApp.Application\CreditApp.Application.csproj" />
<ProjectReference Include="..\CreditApp.Domain\CreditApp.Domain.csproj" />
<ProjectReference Include="..\CreditApp.Infrastructure\CreditApp.Infrastructure.csproj" />
<ProjectReference Include="..\CreditApp\CreditApp.ServiceDefaults\CreditApp.ServiceDefaults.csproj" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Референс на проект есть, но код из него нигде не используется

@DanilSukach DanilSukach requested a review from danlla February 27, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

In progress Код в процессе проверки Lab 1 Лабораторная №1. Кэширование

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants